//
//  SignInViewController.m
//  ShareNavigation
//
//  Created by 水木 傅 on 12-5-4.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "SignInViewController.h"
#import "PickImageViewController.h"

@implementation SignInViewController

@synthesize mapView;
@synthesize search;
@synthesize currentUserLocation;

-(void)viewDidLoad
{
    NSLog(@"%@",[BMKMapView description]);
    [super viewDidLoad];
    mapView.delegate = self;
    search = [[BMKSearch alloc] init];
    search.delegate = self;
    [mapView setShowsUserLocation:YES];
    //self.currentUserLocation = [[BMKUserLocation alloc] init];
}

//---  传递数据给下一个界面  ----
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([segue.identifier isEqualToString:@"ShowImagePicker"])
    {
       // /*------
       // CLLocationCoordinate2D coor;
       // coor.longitude = 119.271785;
       // coor.latitude = 26.112877;
       // [self.currentUserLocation setCoordinate:coor];
      //  -----------*/
        PickImageViewController *controller = (PickImageViewController *)segue.destinationViewController;
        controller.currentUserLocation = self.currentUserLocation;
    }
}

#pragma  ---  百度地图委托  ---

//---  开始定位  ---
-(void)mapViewWillStartLocatingUser:(BMKMapView *)mapView
{
    NSLog(@"开始定位");
}

//---  更新坐标  ---
-(void)mapView:(BMKMapView *)mapView didUpdateUserLocation:(BMKUserLocation *)userLocation
{
    NSLog(@"更新坐标");
    //---  定位在view的中心  ----
    BMKCoordinateRegion region;
    region.center.latitude = userLocation.location.coordinate.latitude;
    region.center.longitude = userLocation.location.coordinate.longitude;
    currentUserLocation = userLocation;
    //---  表示一个经纬度区域?  ---
    region.span.latitudeDelta = 0.25;
    region.span.longitudeDelta = 0.25;
    [self mapView].showsUserLocation = NO;
    NSLog(@"%f ++++  %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
    //---  将界面当前界面移到所定位地方  --- 
    [self mapView].region   = region;
    //添加一个动态点
    BMKPointAnnotation *annotation = [[BMKPointAnnotation alloc] init]; 
    annotation.coordinate = region.center;
    annotation.title = @"现在所处位置";
    [[self mapView] addAnnotation:annotation];
}

//---  定位失败  ---
-(void)mapView:(BMKMapView *)mapView didFailToLocateUserWithError:(NSError *)error{
    
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"警告"
                                                   message:@"定位失败" 
                                                  delegate:self 
                                         cancelButtonTitle:@"返回" 
                                         otherButtonTitles: nil ];
    [alert show];
    [[self mapView] setShowsUserLocation:NO];
    
}

//定位停止

-(void)mapViewDidStopLocatingUser:(BMKMapView *)mapView{    
    NSLog(@"定位停止");  
}


- (void)viewDidUnload {
    [self setMapView:nil];
    [self setMapView:nil];
    [super viewDidUnload];
}
@end












